import os
import sys
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(PROJECT_ROOT)

from conf.setting import FILE_PATH
import configparser

class OperationConfig:
    # 封装读取ini配置文件

    def __init__(self,file_path=None):
        if file_path is None:
            self.__file_path=FILE_PATH['conf']
        else:
            self.__file_path=file_path

        self.conf=configparser.ConfigParser()
        try:
            self.conf.read(self.__file_path,encoding='utf-8')
        except Exception as e:
            print(e)

    def get_section_for_data(self,section,option):
        """
        读取ini数据
        section : ini头部值
        option : 选项值的key
        """
        try:
            data=self.conf.get(section,option)
            return data
        except Exception as e:
            print(e)

    def get_envi(self,option):
        # 获取接口服务器ip地址
        return self.get_section_for_data('api_envi',option)
    
    def get_mysql_conf(self, option):
        # 获取接口服务器ip地址
        return self.get_section_for_data('MYSQL',option)

